<?php
/**
 * Holds class MyIterator
 *
 * @author daantimmer
 *
 * @package Library
 */

/**
 * Iterator class.
 *
 * Iterator class that makes it possible to use any class that
 * implements IteratorAggregate to be used in a foreach statement.
 *
 * @author daantimmer
 *
 * @see Iterator
 */
class MyIterator implements Iterator {
    private $position = 0;
    private $array = array();
    
    public function __construct(array $items) {
        $this->array = $items;
    }

    function rewind() {
        $this->position = 0;
    }

    function current() {
        return $this->array[$this->position];
    }

    function key() {
        return $this->position;
    }

    function next() {
        ++$this->position;
    }

    function valid() {
        return isset($this->array[$this->position]);
    }
}